import Index from "@/pages/frontend/index.vue";
import Login from "@/pages/admin/login.vue";
import AdminIndex from "@/pages/admin/index.vue";
import { createRouter, createWebHashHistory } from "vue-router";
import Admin from "@/layouts/admin/admin.vue";
import AdminArticleList from "@/pages/admin/article-list.vue";
import AdminCategoryList from "@/pages/admin/category-list.vue";
import AdminTagList from "@/pages/admin/tag-list.vue";
import AdminBlogSetting from "@/pages/admin/blog-setting.vue";
import ArchiveList from "@/pages/frontend/archive-list.vue";
import CategoryList from "@/pages/frontend/category-list.vue";
import CategoryPageList from "@/pages/frontend/category-article-list.vue";
import TagList from "@/pages/frontend/tag-list.vue";
import TagArticleList from "@/pages/frontend/tag-article-list.vue";
import ArticleDetail from "@/pages/frontend/article-detail.vue";
import NotFound from "@/pages/frontend/404.vue";


// 定义路由
const routes = [
  {
    // 路径为空字符串，组件为Index
    path: "/",
    component: Index,
    meta: {
      // 路由元信息，标题为'Weblog 首页'
      title: "离悸丶的博客",
    },
  },
  {
    // 路径为空字符串，组件为Index
    path: "/login",
    component: Login,
    meta: {
      // 路由元信息，标题为'Weblog 首页'
      title: "登录",
    },
  },
  {
    path: "/archive/list",
    component: ArchiveList,
    meta: {
      title: "归档",
    },
  },
  {
    path: "/category/list",
    component: CategoryList,
    meta: {
      title: "分类",
    },
  },
  {
    path: "/category/article/list",
    component: CategoryPageList,
    meta: {
      title: "分类文章",
    },
  },
  {
    path: "/tag/list",
    component: TagList,
    meta: {
      title: "标签列表",
    },
  },
  {
    path: "/tag/article/list",
    component: TagArticleList,
    meta: {
      title: "标签文章",
    },
  },
  {
    path: "/article/:articleId",
    component: ArticleDetail,
    meta: {
      title: "详情",
    },
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: NotFound,
    meta: {
      title: "404 Not Found",
    },
  },
  {
    path: "/admin",
    component: Admin,
    // 使用到 admin.vue 布局的，都需要放置在其子路由下面
    children: [
      {
        path: "/admin/index",
        component: AdminIndex,
        meta: {
          title: "仪表盘",
        },
      },
      {
        path: "/admin/article/list",
        component: AdminArticleList,
        meta: {
          title: "文章管理",
        },
      },
      {
        path: "/admin/category/list",
        component: AdminCategoryList,
        meta: {
          title: "分类管理",
        },
      },
      {
        path: "/admin/tag/list",
        component: AdminTagList,
        meta: {
          title: "标签管理",
        },
      },
      {
        path: "/admin/blog/setting",
        component: AdminBlogSetting,
        meta: {
          title: "博客设置",
        },
      },
    ],
  },
];

// 创建路由对象
const router = createRouter({
  // 使用createWebHashHistory创建路由历史对象
  history: createWebHashHistory(),
  // 使用定义的路由
  routes,
  //当路由改变时，将页面滚动到顶部
  scrollBehavior() {
    return { top: 0 }
  }
});

// 导出路由对象
export default router;
